import React from 'react';
import { Breadcrumb } from 'antd';
import { withRouter, Link } from 'dva/router';

function CustomBreadcrumb({ location }) {
  const pathSnippets = location.pathname.split('/').filter(i => i);
  const extraBreadcrumbItems = pathSnippets.map((_, index) => {
    const url = `/${pathSnippets.slice(0, index + 1).join('/')}`;
    return (
      <Breadcrumb.Item key={url}>
        <Link to={url}>
          {pathSnippets[index]}
        </Link>
      </Breadcrumb.Item>
    );
  });
  const breadcrumbItems = [(
    <Breadcrumb.Item key="home">
      <Link to="/">Home</Link>
    </Breadcrumb.Item>
  )].concat(extraBreadcrumbItems);

  return (<Breadcrumb style={{ padding: '12px' }}>
    {breadcrumbItems}
  </Breadcrumb>);
}
export default withRouter(CustomBreadcrumb);
